package com.yunji.storage.business;

import com.yunji.base.cache.BaseCache;
import com.yunji.base.domain.BelongDO;
import com.yunji.base.enums.AuditStatus;
import com.yunji.base.enums.SystemName;
import com.yunji.common.base.BaseBusiness;
import com.yunji.common.constant.LogicCode;
import com.yunji.common.enums.common.ErrorEnum;
import com.yunji.common.enums.common.UserType;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.common.utils.DecimalUtils;
import com.yunji.common.utils.TimeUtils;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.common.utils.uuid.UUIDUtils;
import com.yunji.storage.bo.DiscardInfoListQueryBO;
import com.yunji.storage.bo.DiscardRemoveBO;
import com.yunji.storage.bo.DiscardSelectQueryBO;
import com.yunji.storage.bo.StorageUpdateAuditBO;
import com.yunji.storage.consumer.StockConsumer;
import com.yunji.storage.domain.DiscardInfoDO;
import com.yunji.storage.domain.DiscardTicketDO;
import com.yunji.storage.domain.StockDO;
import com.yunji.storage.dto.DiscardTicketDTO;
import com.yunji.storage.enums.DiscardStatus;
import com.yunji.storage.enums.DraftStatus;
import com.yunji.storage.provide.StockProvide;
import com.yunji.storage.service.IDiscardInfoService;
import com.yunji.storage.service.IDiscardTicketService;
import com.yunji.storage.vo.DiscardTicketVO;
import com.yunji.system.service.TokenService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.storage.business
 * @Title: DiscardTicketBusiness
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-08-24 11:21:28      V1.0        HuaAo       新建类
 */
@Component
public class DiscardTicketBusiness extends BaseBusiness {

    @Resource
    StorageBusiness business;

    @Resource
    IDiscardTicketService discardTicketService;

    @Resource
    IDiscardInfoService discardInfoService;

    @Resource
    StockConsumer stockConsumer;

    @Resource
    StockProvide stockProvide;

    @Resource
    TokenService tokenService;

    /**
     * 新增报废单
     *
     * @param dto
     */
    @Transactional
    public Long create(DiscardTicketDTO dto) {
        //已提交  提交时间和状态
        logs.info("【新增报废单】报废单信息:{}", dto);
        checkDiscardTicket(dto);

        LoginInfo user = tokenService.getUser();
        Long userId = user.getUserId();
        String userType = user.getUserType();
        Long belongId = user.getBelongId();
        logs.info("【新增报废单】当前用户ID:{},当前用户类型:{},当前用户所属ID:{}", userId, userType, belongId);
        Assert.isTrue(BeanUtils.isNotNull(belongId), ErrorEnum.BUSINESS_121003.getText());


        BelongDO vo = BaseCache.getBelong(belongId);
        logs.info("【新增报废单】当前用户所属信息:{}", vo);
        Assert.isTrue(BeanUtils.isNotNull(vo), ErrorEnum.BUSINESS_121004.getText());

        DiscardTicketDO discardTicket = new DiscardTicketDO();
        BeanUtils.clone(dto, discardTicket);
        discardTicket.setBelongId(belongId);
        discardTicket.setApplyId(userId);
        discardTicket.setApplyName(user.getNickname());
        discardTicket.setApplyBelongId(belongId);
        discardTicket.setApplyBelongName(vo.getBelongName());

        String discardCode = UUIDUtils.discardCode();
        logs.info("【新增报废单】报废单号:{}", discardCode);
        discardTicket.setDiscardStatus(DiscardStatus.COMMIT.getCode());
        Date time = TimeUtils.getNowDate();
        logs.info("【新增报废单】提交时间:{}", time);
        discardTicket.setApplyTime(time);

        discardTicket.setCreateTime(time);
        discardTicket.setDiscardCode(discardCode);

        if (!Objects.equals(UserType.PLATE.getCode(), userType)) {
            Assert.isTrue(discardTicketService.create(discardTicket), "新增失败");
            handleInfoList(discardTicket, dto.getInfoList(), true);
            StorageUpdateAuditBO auditBO = new StorageUpdateAuditBO();
            auditBO.setBusinessId(discardTicket.getDiscardId());
            auditBO.setAuditStatus(AuditStatus.WAIT.getCode());
            discardTicketService.updateAuditStatus(auditBO);
            return 1L;
        }

        Assert.isTrue(discardTicketService.create(discardTicket), "新增失败");

        handleInfoList(discardTicket, dto.getInfoList(), true);

        business.handleDiscardStorageTicket(discardTicket, dto.getInfoList());

        StorageUpdateAuditBO auditBO = new StorageUpdateAuditBO();
        auditBO.setBusinessId(discardTicket.getDiscardId());
        auditBO.setAuditStatus(AuditStatus.ACCEPT.getCode());
        auditBO.setAuditBelongId(belongId);
        auditBO.setAuditBelongName(SystemName.ENABLED.getText());
        auditBO.setAuditId(userId);
        auditBO.setAuditName(user.getNickname());
        auditBO.setAuditTime(TimeUtils.getNowDate());
        discardTicketService.updateAuditStatus(auditBO);

        return discardTicket.getDiscardId();
    }

    /**
     * 报废单详情
     *
     * @param discardId
     * @return
     */
    public DiscardTicketVO select(Long discardId) {
        DiscardTicketVO vo = new DiscardTicketVO();
        DiscardTicketDO ticket = discardTicketService.select(discardId);

        if (BeanUtils.isNull(ticket)) return null;
        BeanUtils.clone(ticket, vo);
        vo.setOutBelongName(BaseCache.getBelongName(vo.getOutBelongId()));
        vo.setParentId(BaseCache.getBelong(vo.getBelongId()).getParentId());
        List<DiscardInfoDO> infoList = discardInfoService.search(new DiscardInfoListQueryBO(discardId));
        vo.setInfoList(infoList);

        return vo;
    }

    /**
     * 保存草稿
     *
     * @param dto
     */
    @Transactional
    public void saveDraft(DiscardTicketDTO dto) {
        logs.info("【保存草稿】草稿信息:{}", dto);

        LoginInfo user = tokenService.getUser();
        Long belongId = user.getBelongId();
        logs.info("【保存草稿】当前用户所属ID:{}", belongId);
        Assert.isTrue(BeanUtils.isNotNull(belongId), ErrorEnum.BUSINESS_121003.getText());

        DiscardTicketDO discardTicket = new DiscardTicketDO();
        BeanUtils.clone(dto, discardTicket);
        discardTicket.setBelongId(belongId);
        String discardCode = UUIDUtils.discardCode();
        logs.info("【保存草稿】调拨单号:{}", discardCode);

        Integer discardStatus = DiscardStatus.DRAFT.getCode();

        //删除之前的草稿
        discardTicketService.deleteByTicket(new DiscardRemoveBO(belongId, discardStatus));

        discardTicket.setDiscardStatus(discardStatus);
        discardTicket.setDiscardCode(discardCode);
        Assert.isTrue(discardTicketService.create(discardTicket), "新增失败");

        Long discardId = discardTicket.getDiscardId();
        logs.info("【保存草稿】调拨单ID:{}", discardId);

        //处理调拨草稿详情
        if (BeanUtils.isNotNull(dto.getInfoList())) {
            handleInfoList(discardTicket, dto.getInfoList(), false);
        }
    }

    /**
     * 获取草稿
     *
     * @param belongId
     * @return
     */
    public DiscardTicketVO getDraft(Long belongId) {
        DiscardTicketDO ticket = discardTicketService.select(new DiscardSelectQueryBO(belongId, DiscardStatus.DRAFT.getCode()));
        DiscardTicketVO vo = new DiscardTicketVO();
        if (BeanUtils.isNotNull(ticket)) {
            BeanUtils.clone(ticket, vo);
        }

        Long discardId = vo.getDiscardId();
        logs.info("【获取草稿】报废单ID:{}", discardId);

        if (BeanUtils.isNotNull(discardId)) {
            List<DiscardInfoDO> infoList = discardInfoService.search(new DiscardInfoListQueryBO(discardId));
            vo.setInfoList(infoList);
            vo.setDraftStatus(DraftStatus.EXIST.getCode());
        } else {
            vo.setDraftStatus(DraftStatus.ABSENT.getCode());
        }

        return vo;
    }

    /**
     * 审核报废单
     *
     * @param discardId
     * @param auditStatus
     * @param reason
     */
    @Transactional
    public void audit(Long discardId, Integer auditStatus, String reason) {
        LoginInfo user = tokenService.getUser();
        Long belongId = user.getBelongId();
        logs.info("【审核报废单】当前用户所属ID:{}", belongId);
        Assert.isTrue(BeanUtils.isNotNull(belongId), ErrorEnum.BUSINESS_121003.getText());

        BelongDO belongVO = BaseCache.getBelong(belongId);
        logs.info("【审核报废单】当前用户所属信息:{}", belongVO);
        Assert.isTrue(BeanUtils.isNotNull(belongVO), ErrorEnum.BUSINESS_121004.getText());

        logs.info("【审核报废单】报废单ID:{}", discardId);
        DiscardTicketDO ticket = discardTicketService.select(discardId);
        logs.info("【审核报废单】报废单信息:{}", ticket);
        Assert.isTrue(BeanUtils.isNotNull(ticket), ErrorEnum.BUSINESS_812004.getText());
        Assert.isTrue(Objects.equals(AuditStatus.WAIT.getCode(), ticket.getAuditStatus()), ErrorEnum.BUSINESS_812005.getText());

        DiscardTicketDO update = new DiscardTicketDO();
        update.setDiscardId(discardId);

        List<DiscardInfoDO> infoList = discardInfoService.search(new DiscardInfoListQueryBO(discardId));
        //审核通过 修改单据 并自动出库
        if (Objects.equals(AuditStatus.ACCEPT.getCode(), auditStatus)) {
            business.handleDiscardStorageTicket(ticket, infoList);

            update.setDiscardStatus(DiscardStatus.FINISH.getCode());
        } else {
            //返还库存
            backStock(ticket.getOutBelongId(), infoList);
            update.setDiscardStatus(DiscardStatus.CANCEL.getCode());
            if (BeanUtils.isNotNull(reason)) {
                update.setReason(reason);
            }
        }

        StorageUpdateAuditBO auditBO = new StorageUpdateAuditBO();
        auditBO.setBusinessId(discardId);
        auditBO.setAuditStatus(auditStatus);
        auditBO.setAuditId(user.getUserId());
        auditBO.setAuditName(user.getNickname());
        auditBO.setAuditBelongId(belongVO.getBelongId());
        auditBO.setAuditBelongName(belongVO.getBelongName());
        auditBO.setAuditStatus(auditStatus);

        Date time = TimeUtils.getNowDate();
        update.setAuditTime(time);
        Assert.isTrue(discardTicketService.updateAuditStatus(auditBO),"修改失败");
        Assert.isTrue(discardTicketService.update(update), "修改失败");

    }

    /**
     * 取消报废单
     *
     * @param discardId
     */
    @Transactional
    public void cancel(Long discardId) {
        //待审核报废单可取消
        DiscardTicketDO ticket = discardTicketService.select(discardId);
        logs.info("【取消报废单】报废单信息:{}", ticket);
        Assert.isTrue(BeanUtils.isNotNull(ticket), "未找到报废单");

        Integer discardStatus = ticket.getDiscardStatus();
        Integer auditStatus = ticket.getAuditStatus();
        Assert.isTrue(Objects.equals(DiscardStatus.COMMIT.getCode(), discardStatus) && Objects.equals(AuditStatus.WAIT.getCode(), auditStatus), "当前状态不能取消报废");

        //取消报废单
        DiscardTicketDO update = new DiscardTicketDO();
        update.setDiscardId(discardId);
        update.setDiscardStatus(DiscardStatus.CANCEL.getCode());
        discardTicketService.update(update);

        StorageUpdateAuditBO auditBO = new StorageUpdateAuditBO();
        auditBO.setBusinessId(discardId);
        auditBO.setAuditStatus(AuditStatus.CANCEL.getCode());
        discardTicketService.updateAuditStatus(auditBO);

        //不可用库存扣除 可用库存增加
        List<DiscardInfoDO> infoList = discardInfoService.search(new DiscardInfoListQueryBO(discardId));
        backStock(ticket.getOutBelongId(), infoList);
    }

    /**
     * 重新提交
     *
     * @param dto
     */
    @Transactional
    public void commit(DiscardTicketDTO dto) {
        //草稿重新提交 就是修改报废单并提交
        logs.info("【重新提交报废单】报废单信息:{}", dto);
        checkDiscardTicket(dto);

        Long discardId = dto.getDiscardId();
        Assert.isTrue(BeanUtils.isNotNull(discardId), "未找到报废单ID");

        Integer discardStatus = dto.getDiscardStatus();
        logs.info("【重新提交报废单】报废单状态:{}", discardStatus);
        Assert.isTrue(BeanUtils.equals(discardStatus, DiscardStatus.DRAFT.getCode(), DiscardStatus.CANCEL.getCode()), "当前状态不可提交");

        LoginInfo user = tokenService.getUser();
        Long userId = user.getUserId();
        String userType = user.getUserType();
        Long belongId = user.getBelongId();
        logs.info("【重新提交报废单】当前用户ID:{},当前用户类型:{},当前用户所属ID:{}", userId, userType, belongId);
        Assert.isTrue(BeanUtils.isNotNull(belongId), ErrorEnum.BUSINESS_121003.getText());


        BelongDO vo = BaseCache.getBelong(belongId);
        logs.info("【重新提交报废单】当前用户所属信息:{}", vo);
        Assert.isTrue(BeanUtils.isNotNull(vo), ErrorEnum.BUSINESS_121004.getText());

        DiscardTicketDO discardTicket = new DiscardTicketDO();

        Date time = TimeUtils.getNowDate();
        discardTicket.setDiscardId(dto.getDiscardId());
        discardTicket.setDiscardCode(dto.getDiscardCode());
        discardTicket.setBelongId(dto.getBelongId());
        discardTicket.setOutBelongId(dto.getOutBelongId());
        discardTicket.setAlbumPics(dto.getAlbumPics());
        discardTicket.setBelongId(belongId);
        discardTicket.setApplyId(userId);
        discardTicket.setApplyName(user.getNickname());
        discardTicket.setApplyTime(time);
        discardTicket.setApplyBelongId(belongId);
        discardTicket.setApplyBelongName(vo.getBelongName());
        discardTicket.setDiscardStatus(DiscardStatus.COMMIT.getCode());
        discardTicket.setAuditStatus(AuditStatus.WAIT.getCode());
        if (BeanUtils.isNotNull(dto.getRemark())) {
            discardTicket.setRemark(dto.getRemark());
        }

        Integer auditStatus = dto.getAuditStatus();
        logs.info("【重新提交报废单】审核状态:{}", auditStatus);
        StorageUpdateAuditBO auditBO = new StorageUpdateAuditBO();
        auditBO.setAuditStatus(AuditStatus.WAIT.getCode());

        // 报废状态 - 已取消
        // 审核状态 - 通过
        //        - 驳回
        // 重新生成单据
        if (Objects.equals(DiscardStatus.CANCEL.getCode(), discardStatus) && BeanUtils.isNotNull(auditStatus)) {
            // 管理员无需审核
            if (Objects.equals(UserType.PLATE.getCode(), userType)) {
                discardTicket.setDiscardStatus(DiscardStatus.FINISH.getCode());

                Long id = handleCancelTicket(dto, discardTicket);
                auditBO.setBusinessId(id);
                auditBO.setAuditId(userId);
                auditBO.setAuditName(user.getNickname());
                auditBO.setAuditBelongId(belongId);
                auditBO.setAuditBelongName(SystemName.ENABLED.getText());
                auditBO.setAuditTime(time);
                auditBO.setAuditStatus(AuditStatus.ACCEPT.getCode());

                business.handleDiscardStorageTicket(discardTicket, dto.getInfoList());
            } else {
                // 非管理员重新提交单据
                Long id = handleCancelTicket(dto, discardTicket);
                auditBO.setBusinessId(id);
            }
        } else {
            // 盘点状态  - 草稿状态
            //         - 已取消状态
            // 审核状态  - 空
            // 提交原来单据
            if (Objects.equals(UserType.PLATE.getCode(), userType)) {
                // 管理员提交草稿
                discardTicket.setDiscardStatus(DiscardStatus.FINISH.getCode());

                Assert.isTrue(discardTicketService.update(discardTicket), "修改失败");
                auditBO.setBusinessId(discardTicket.getDiscardId());
                auditBO.setAuditId(userId);
                auditBO.setAuditName(user.getNickname());
                auditBO.setAuditBelongId(belongId);
                auditBO.setAuditBelongName(SystemName.ENABLED.getText());
                auditBO.setAuditTime(time);
                auditBO.setAuditStatus(AuditStatus.ACCEPT.getCode());
                handleInfoList(discardTicket, dto.getInfoList(), true);


                business.handleDiscardStorageTicket(discardTicket, dto.getInfoList());
            } else {
                // 非管理员提交草稿
                Assert.isTrue(discardTicketService.update(discardTicket), "修改失败");
                auditBO.setBusinessId(discardTicket.getDiscardId());
                handleInfoList(discardTicket, dto.getInfoList(), true);
            }
        }
        discardTicketService.updateAuditStatus(auditBO);
    }

    /**
     * 批量删除报废单
     *
     * @param discardIds
     */
    @Transactional
    public void delete(Long... discardIds) {
        discardTicketService.deleteDraft(discardIds);
        discardInfoService.deleteByDiscardIds(discardIds);
    }

    /*---------------------------------------处理/参数校验----------------------------------------*/

    /**
     * 处理报废单详情
     *
     * @param
     * @param infoList
     * @Param checkStatus
     */
    private void handleInfoList(DiscardTicketDO discardTicket, List<DiscardInfoDO> infoList, boolean checkStatus) {
        //先查出来所有  没有就新增 有就修改  其他删除
        List<DiscardInfoDO> list = discardInfoService.search(new DiscardInfoListQueryBO(discardTicket.getDiscardId()));
        logs.info("【处理报废单详情】存在的详情:{}", list);

        List<DiscardInfoDO> createList = new ArrayList<>();
        List<DiscardInfoDO> updateList = new ArrayList<>();
        List<Long> deleteIds = new ArrayList<>();

        //获取当前详情
        for (DiscardInfoDO allocateInfo : list) {
            deleteIds.add(allocateInfo.getInfoId());
        }

        //处理详情
        for (DiscardInfoDO discardInfo : infoList) {
            discardInfo.setBelongId(discardTicket.getBelongId());
            discardInfo.setDiscardId(discardTicket.getDiscardId());
            discardInfo.setDiscardCode(discardTicket.getDiscardCode());

            //非草稿状态都需要检验
            if (checkStatus) {
                checkDiscardInfo(discardInfo);
                business.checkDiscardStock(discardTicket, discardInfo);
            }
            //进行修改的详情
            Long infoId = discardInfo.getInfoId();
            logs.info("【处理报废单详情】详情ID:{}", infoId);
            if (BeanUtils.isNotNull(discardInfo.getInfoId())) {
                //进行修改的剔除删除行列
                updateList.add(discardInfo);
                if (deleteIds.contains(infoId)) {
                    deleteIds.remove(infoId);
                }
            } else {
                createList.add(discardInfo);
            }
        }

        logs.info("【处理报废单详情】删除详情Ids:{}", deleteIds);

        Assert.isTrue(discardInfoService.deleteByInfoIds(deleteIds), "删除失败");

        logs.info("【处理报废单详情】新增报废单详情:{}", createList);
        for (DiscardInfoDO create : createList) {
            Assert.isTrue(discardInfoService.create(create), "新增失败");
        }

        logs.info("【处理报废单详情】修改报废单详情:{}", updateList);
        for (DiscardInfoDO update : updateList) {
            discardInfoService.update(update);
        }
    }


    /**
     * 处理取消状态报废单
     */
    private Long handleCancelTicket(DiscardTicketDTO dto, DiscardTicketDO discardTicket) {
        Long discardId = dto.getDiscardId();
        logs.info("【处理取消状态报废单】单据ID:{}", discardId);
        Integer discardStatus = DiscardStatus.SCRAP.getCode();
        DiscardTicketDO update = new DiscardTicketDO();
        update.setDiscardId(discardId);
        update.setDiscardStatus(discardStatus);
        Assert.isTrue(discardTicketService.update(update), "修改失败");

        String discardCode = UUIDUtils.discardCode();
        discardTicket.setDiscardCode(discardCode);
        DiscardTicketDO createTicket = new DiscardTicketDO();
        BeanUtils.clone(discardTicket, createTicket);
        createTicket.setDiscardId(null);
        Assert.isTrue(discardTicketService.create(createTicket), "新增失败");

        List<DiscardInfoDO> infoList = dto.getInfoList();
        logs.info("【处理取消状态报废单】商品信息:{}", infoList);

        List<DiscardInfoDO> createList = new ArrayList<>();

        for (DiscardInfoDO discardInfo : infoList) {
            checkDiscardInfo(discardInfo);
            DiscardInfoDO info = new DiscardInfoDO();
            BeanUtils.clone(discardInfo, info);

            info.setInfoId(null);
            info.setDiscardId(createTicket.getDiscardId());
            info.setDiscardCode(createTicket.getDiscardCode());
            business.checkDiscardStock(createTicket, info);
            createList.add(info);
        }

        for (DiscardInfoDO create : createList) {
            Assert.isTrue(discardInfoService.create(create), "新增失败");
        }

        return createTicket.getDiscardId();
    }

    /**
     * 库存返还
     *
     * @param belongId
     * @param infoList
     */
    private void backStock(Long belongId, List<DiscardInfoDO> infoList) {
        Integer stockStatus = stockConsumer.getStockStatus(belongId);

        if (Objects.equals(LogicCode.YES, stockStatus)) {
            List<StockDO> stockList = new ArrayList<>();

            for (DiscardInfoDO discardInfo : infoList) {
                StockDO stock = new StockDO();
                stock.setBelongId(belongId);
                stock.setProductId(discardInfo.getProductId());
                stock.setDisableStock(discardInfo.getDiscardAmount().negate());
                stock.setUsableStock(discardInfo.getDiscardAmount());
                stock.setAllStock(BigDecimal.ZERO);
                stock.setFrozenStock(BigDecimal.ZERO);
                stockList.add(stock);
            }

            stockProvide.handleStock(stockList);
        }
    }

    /**
     * 校验报废单参数
     *
     * @param dto
     */
    private void checkDiscardTicket(DiscardTicketDTO dto) {
        Long outBelongId = dto.getOutBelongId();
        String albumPics = dto.getAlbumPics();
        List<DiscardInfoDO> infoList = dto.getInfoList();

        logs.info("【报废单校验】出库单位:{}", outBelongId);
        logs.info("【报废单校验】照片:{}", albumPics);
        logs.info("【报废单校验】商品信息:{}", infoList);

        Assert.isTrue(BeanUtils.isNotNull(outBelongId), ErrorEnum.CHECKED_811016.getText());
        Assert.isTrue(BeanUtils.isNotNull(albumPics), ErrorEnum.CHECKED_811017.getText());
        Assert.isTrue(BeanUtils.isNotNull(infoList), ErrorEnum.CHECKED_811003.getText());
    }

    /**
     * 校验报废详情参数
     *
     * @param dto
     */
    private void checkDiscardInfo(DiscardInfoDO dto) {
        Long productId = dto.getProductId();
        String productSku = dto.getProductSku();
        String productName = dto.getProductName();
        BigDecimal discardAmount = dto.getDiscardAmount();
        Long unitId = dto.getUnitId();

        logs.info("【商品参数校验】商品ID:{}", productId);
        logs.info("【商品参数校验】商品sku:{}", productSku);
        logs.info("【商品参数校验】商品名称:{}", productName);
        logs.info("【商品参数校验】报废数量:{}", discardAmount);
        logs.info("【商品参数校验】商品单位:{}", unitId);

        Assert.isTrue(BeanUtils.isNotNull(dto.getProductId()), ErrorEnum.CHECKED_811003.getText());
        Assert.isTrue(BeanUtils.isNotNull(dto.getProductSku()), ErrorEnum.CHECKED_811003.getText());
        Assert.isTrue(BeanUtils.isNotNull(dto.getProductName()), ErrorEnum.CHECKED_811003.getText());
        Assert.isTrue(BeanUtils.isNotNull(dto.getDiscardAmount()), ErrorEnum.CHECKED_811015.getText());
        Assert.isTrue(BeanUtils.isNotNull(dto.getUnitId()), ErrorEnum.CHECKED_811003.getText());
        Assert.isTrue(DecimalUtils.more(discardAmount, BigDecimal.ZERO), ErrorEnum.CHECKED_811012.getText());
    }

}